/**
 *
 */
package org.insia.smartposse.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.insia.smartposse.mapping.dao._RootDAO;

/**
 * Filter for create and manage the connection with database
 *
 * @author cmougel
 */
public class FilterMaster
implements Filter
{
	/*
	 * (non-Javadoc)
	 *
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
	 */
	public void init(FilterConfig arg0)
	throws ServletException {
		_RootDAO.initialize();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
	 *      javax.servlet.ServletResponse, javax.servlet.FilterChain) Define the
	 *      userIdentification value in req
	 */
	public void doFilter(ServletRequest req, ServletResponse resp,
		FilterChain chain)
	throws IOException, ServletException {
		chain.doFilter(req, resp);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see javax.servlet.Filter#destroy()
	 */
	public void destroy() {
		_RootDAO.closeCurrentSession();

	}

}
